package algotithm.leetcode.presum.test1744;

/**
 * @author 25068
 * @Date 2021/6/1 9:37
 * @Title 1744. 你能在你最喜欢的那天吃到你最喜欢的糖果吗？
 */
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] candiesCount = {7,4,5,3,8};
        int[][] queries = {{0,2,2},{4,2,4},{2,13,1000000000}};
        boolean[] res = solution.canEat(candiesCount, queries);
        for (int i = 0; i < res.length; i++) {
            System.out.print(res[i] + " ");
        }
    }

    public boolean[] canEat(int[] candiesCount, int[][] queries) {
        int n = candiesCount.length;
        long[] sum = new long[n];
        sum[0] = candiesCount[0];
        for (int i = 1; i < n; i++) {
            sum[i] = sum[i-1] + candiesCount[i];
        }

        int m = queries.length;
        boolean[] ans = new boolean[m];
        for (int i = 0; i < m; i++) {
            int[] query = queries[i];
            int faType = query[0];
            int faDay = query[1];
            int daCap = query[2];
            long x1 = faDay + 1;
            long x2 = (long) (faDay + 1) * daCap;
            long y1 = faType == 0 ? 1 : sum[faType - 1] + 1;
            long y2 = sum[faType];
            ans[i] = !(x1 > y2 || x2 < y1);
        }
        return ans;
    }
}

